package com.lam.common.validate.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.lam.common.utils.StringUtils;
import com.lam.common.validate.annotation.DictCheck;

public class DictValidator implements ConstraintValidator<DictCheck, Object> {
	
	@Override
	public boolean isValid(Object value, ConstraintValidatorContext context) {
		
		String msg = DictValidBean.newInstance(value.getClass()).check(value);
		if(StringUtils.isBlank(msg)) {
			return true;
		}
		
		//禁用默认的message的值
        context.disableDefaultConstraintViolation();
        //重新添加错误提示语句
        context.buildConstraintViolationWithTemplate(msg).addConstraintViolation();
		return false;
	}
	
}
